<?php
// 导游类
class Guider extends User_V2_Member
{
    public function __construct ($uid = NULL, $userinfo = NULL)
    {
        $this->_uid = $uid;
        $this->_userinfo = NULL;

        parent::__construct ($uid, $userinfo);
    }

    public function getRealName ()
    {
        $userinfo = $this->getUserInfo();
        return Arr::get($userinfo, 'realName');
    }

    public function getUserInfo ()
    {
        $baseInfo = parent::getUserInfo();
        $userInfo = Util_User::getUserInfo($this->_uid);
        $info  = $this->loadUserInfo();
        $key_info = array("telActive","identityActive","active",'telCode','telNum','identityErea','identityName','identityPicture','email','failMsg','utype');

         foreach($key_info as $v)
         {
             $baseInfo[$v] = Arr::get($info,$v);
         }
        if($baseInfo['identityName'] == '留学生'){
            $data = explode('-|-',$baseInfo['identityErea']);
            $baseInfo['identityErea_zhuanye'] = Arr::get($data,0);
            $baseInfo['identityErea_school'] = Arr::get($data,1);
        }

        $key_user_info = array('userAge','nationality','language','introduction','resideCity','resideTime','country','code','rcity','addr','userGender');

        foreach($key_user_info as $v)
        {
            $baseInfo[$v] = Arr::get($userInfo,$v);
        }

        $baseInfo['realName'] = Arr::get($userInfo,"userFamily").Arr::get($userInfo,'userName');

        $this->_userinfo = $baseInfo;
        return $baseInfo;
    }

    public function optionsAllGuiders ()
    {
        $query = DB::select('u.uid', 'i.userFamily', 'i.userName')
            ->from(array('user_v2', 'u'))
            ->join(array('user_v2_userinfo', 'i'), 'LEFT')
            ->on('u.uid', '=', 'i.uid')
            ->where('u.utype', '=', 'GUIDER')
            ->order_by('u.uid', 'asc')
            ->execute();

        $guiders = array();
        foreach ($query as $rs)
        {
            $guiders[$rs['uid']] = $rs['userFamily'] . $rs['userName'];
        }

        return $guiders;
    }

    protected function loadUserInfo ()
    {
        $query = DB::select()
            ->from('user_v2')
            ->where('uid', '=', (int) $this->_uid)
            ->execute();

        if ($query->count() > 0)
        {
            $current = $query->current();
            $uid     = $current['uid'];
            $status  = $current['status'];
            if ($status != 1)
                $this->_userinfo = array();
            else
                $this->_userinfo = $current;
        }
        else
        {
            $this->_userinfo = array();
        }
        return $this->_userinfo;
    }

}


